package com.yc.snacknet_vue.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yc.snacknet_vue.bean.GoodsInfo;
import com.yc.snacknet_vue.biz.IGoodsInfoBiz;
import com.yc.snacknet_vue.biz.Impl.GoodsInfoBizImpl;
import com.yc.snacknet_vue.dao.IGoodsInfoDAO;

/**
 * 商品业务控制层
 * @author UNO
 * @date 2021年8月9日
 * Email 2759451734@qq.com
 */
@WebServlet("/goods/*")
public class GoodsInfoController extends BaseServlet{

	private static final long serialVersionUID = 1L;

	//前台的第一次分页查询 生成页码数
	protected void findByFirst(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String gname = request.getParameter("gname");
		String tno = request.getParameter("tno");
		String sprice = request.getParameter("sprice");
		String eprice = request.getParameter("eprice");
		String order = request.getParameter("order");

		int page = Integer.parseInt(request.getParameter("page"));
		int rows = Integer.parseInt(request.getParameter("rows"));
		IGoodsInfoBiz biz = new GoodsInfoBizImpl();
		Map<String, Object> map = biz.findByFirst(gname, tno, sprice, eprice, page, rows, order);
		if(null == map || map.isEmpty()) {
			this.send(response, 500, null);
			return;
		}
		this.send(response, 200, map);
	}
	//前台后续分页查询 
	protected void finds(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String gname = request.getParameter("gname");
		String tno = request.getParameter("tno");
		String sprice = request.getParameter("sprice");
		String eprice = request.getParameter("eprice");
		String order = request.getParameter("order");

		int page = Integer.parseInt(request.getParameter("page"));
		int rows = Integer.parseInt(request.getParameter("rows"));

		IGoodsInfoBiz biz = new GoodsInfoBizImpl();
		List<GoodsInfo> list = biz.finds(gname, tno, sprice, eprice, page, rows, order);
		if(null == list || list.isEmpty()) {
			this.send(response, 500, null);
			return;
		}
		this.send(response, 200, list);
	}

	//商品编号详情查询
	protected void findByGno(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String gno = request.getParameter("gno");
		IGoodsInfoBiz biz = new GoodsInfoBizImpl();
		GoodsInfo goods = biz.findByGno(gno);
		if(null == goods) {
			this.send(response, 500, null);
			return;
		}
		this.send(response, 200, goods);
	}
}
